﻿////////////////////////////////////////////////////////////////////////////////
// Source Copyright (C) J.Fan
// @author      J.Fan
// @date        2013-02-08
// @revision    Revision in Version Control System
// @remark      
////////////////////////////////////////////////////////////////////////////////

using JsonConverter.Writer;

namespace JsonConverter.Converter
{
    public abstract class JavaScriptObjectConverter: IObjectConverter
    {
        protected JsonWriter Writer { get; private set; }

        public virtual void Convert(JsonWriter writer, object obj)
        {
            this.Writer = writer;

            BeginObject();
            OnConvertObject(obj);
            EndObject();
        }

        protected abstract void OnConvertObject(object obj);

        protected virtual void BeginObject()
        {
            Writer.WriteLiteral("{");
        }

        protected virtual void EndObject()
        {
            Writer.WriteLiteral("}");
        }
    }
}
